home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / graphics 2d / makeicon / makeicon.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.5 KB  |  136 lines

  1. /*
  2.     File:        MakeIcon.c
  3.  
  4.     Contains:    this program shows how to take any size pixmap and scale it down to any size or
  5.                 depth icon.
  6.  
  7.     Written by: Brigham Stevens    
  8.  
  9.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 7/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24. #include <QDOffScreen.h>
  25. #include "IconUtil.h"
  26. #include "InitMac.h"
  27. #include <Windows.h>
  28. #include <Resources.h>
  29. #include "MiscCode.h"
  30. #define ICONID 128
  31.  
  32. void main()
  33. {
  34.  
  35.     WindowPtr    cwp;
  36.     Handle        icon;
  37.     GWorldPtr    gwp;
  38.     Rect        demo;
  39.     short        ref;
  40.     
  41.     
  42.     InitToolBox(4);                    // Witch Chant + 4 calls to More Masters
  43.     
  44.     /* load map of earth in color - no hilite palette */
  45.     cwp = GetNewCWindow(128,nil,(void*)-1L);
  46.     gwp = LoadPictToGWorld(128, cwp, 256, 8, 8, true);    
  47.     SetWTitle(cwp,"\pFlailing about rapidly contorting");
  48.     ShowWindow(cwp);
  49.     DrawImage(cwp);
  50.  
  51.     while(!Button());                    // after a click then we make a small icon thang....
  52.     FlushEvents(everyEvent,0);
  53.     SetRect(&demo,100,100,132,132);        // this is the area of pixmap we make icon from
  54.                                         // it can be the entire portRect if we want
  55.     
  56.     
  57.     
  58.     ref = OpenResFile("\pMakeIcon.output");        // THIS FILE MUST EXIST, or we may croak
  59.     if(ResError())    ExitToShell();
  60.     
  61.     icon = MakeIcon(gwp,&demo,1,32);            // make 32x32 1-bit color icon
  62.     
  63.     if(icon)
  64.     {
  65.         TryRemoveResource('ICON',ICONID);
  66.         AddResource( icon, 'ICON', ICONID, "\p");
  67.         CheckError("\pAddResFail ICON",ResError());
  68.     }
  69.  
  70.     icon = MakeIcon(gwp,&demo,1,16);            // make 16x16 1-bit color icon
  71.     
  72.     if(icon)
  73.     {
  74.         TryRemoveResource('SICN',ICONID);
  75.         AddResource( icon, 'SICN', ICONID, "\p");
  76.         CheckError("\pAddResFail SICN",ResError());
  77.     }
  78.  
  79.     icon =    MakeICN_pound(gwp, &demo, 32);        // create 32x32 1-bit color icon AND MASK
  80.     if(icon)
  81.     {
  82.         TryRemoveResource('ICN#',ICONID);
  83.         AddResource( icon, 'ICN#', ICONID, "\p");
  84.         CheckError("\pAddResFail ICN#",ResError());
  85.     }
  86.  
  87.     icon =    MakeICN_pound(gwp, &demo, 16);        // create 16x16 1-bit color icon AND MASK
  88.     if(icon)
  89.     {
  90.         TryRemoveResource('ics#',ICONID);
  91.         AddResource( icon, 'ics#', ICONID, "\p");
  92.         CheckError("\pAddResFail ics#",ResError());
  93.     }
  94.  
  95.     icon = MakeIcon(gwp,&demo,8,32);            // make 32x32 8-bit color icon
  96.     
  97.     if(icon)
  98.     {
  99.         TryRemoveResource('icl8',ICONID);
  100.         AddResource( icon, 'icl8', ICONID, "\p");
  101.         CheckError("\pAddResFail icl8",ResError());
  102.     }
  103.  
  104.     icon = MakeIcon(gwp,&demo,4,32);            // make 32x32 4-bit color icon
  105.     
  106.     if(icon)
  107.     {
  108.         TryRemoveResource('icl4',ICONID);
  109.         AddResource( icon, 'icl4', ICONID, "\p");
  110.         CheckError("\pAddResFail icl4",ResError());
  111.     }
  112.  
  113.  
  114.     icon = MakeIcon(gwp,&demo,8,16);                // make 16x16 8-bit color mask
  115.     
  116.     if(icon)
  117.     {
  118.         TryRemoveResource('ics8',ICONID);
  119.         AddResource( icon, 'ics8', ICONID, "\p");
  120.         CheckError("\pAddResFail ics8",ResError());
  121.     }
  122.  
  123.     icon = MakeIcon(gwp,&demo,4,16);                // make 16x16 4-bit color mask
  124.     
  125.     if(icon)
  126.     {
  127.         TryRemoveResource('ics4',ICONID);
  128.         AddResource( icon, 'ics4', ICONID, "\p");
  129.         CheckError("\pAddResFail ics4",ResError());
  130.     }
  131.  
  132.     CloseResFile(ref);
  133. }
  134.  
  135.  
  136.